class Solution {
public:
    ListNode *removeNthFromEnd(ListNode *head, int n)
    {
        ListNode *p1, *p2;
        if(!head->next) {
            return NULL;
        }
        p1 = head;
        p2 = head;
        while(n--) {
            p1 = p1->next;
        }
        if(!p1) {
            return head->next;
        }
        while(p1->next) {
            p1 = p1->next;
            p2 = p2->next;
        }
        if(!p2->next) {

        }
        p2->next = p2->next->next;
        return head;
    }
};